package com.tianyang.yukuaifuzs.business.main.adapter;

import android.net.Uri;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.main.bean.ChannelOutput;
import com.tianyang.yukuaifuzs.utils.VerifyUtil;

import java.util.ArrayList;

/**
 * Description：渠道
 * Created by xyj on 2024/6/15
 */
public class ChannelAdapter extends BaseQuickAdapter<ChannelOutput, BaseViewHolder> {

    private int chooseIndex = 0;

    public ChannelAdapter() {
        super(R.layout.item_pos_channel, new ArrayList<>());
    }

    public void setChooseIndex(int index) {
        this.chooseIndex = index;
        this.notifyDataSetChanged();
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ChannelOutput item) {
        if (item != null) {
            helper.setText(R.id.nameTv, VerifyUtil.checkString(item.getName()))
                    .setVisible(R.id.leftView, helper.getLayoutPosition() == 0);
            SimpleDraweeView imgSdv = helper.getView(R.id.imgSdv);
            if (!TextUtils.isEmpty(item.getIcon())) {
                imgSdv.setImageURI(Uri.parse(item.getIcon()));
            }
            TextView nameTv = helper.getView(R.id.nameTv);
            if (helper.getLayoutPosition() == chooseIndex) {
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.color_base));
            } else {
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_333333));
            }
        }
    }
}
